#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMediaPlayer>
#include <QMainWindow>
#include <QIcon>
#include <QSize>
#include <QPainter>
#include <QString>
#include <QPushButton>
#include <QPixmap>
#include <QVBoxLayout>
#include <QAudioOutput>
#include <QDir>
#include <QList>
#include <QVector>
#include <QListWidgetItem>
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    struct LyricLine {
        qint64 time;    // 当前时间(毫秒)
        QString text;    // 歌词文本
        int index;       // 行号
    };
    enum musicmodel{
        ORDER,RAND
    };
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
private:
    void init();
    void setbackground();
    void initbuticon(QPushButton* but,QString url);
    void showmusiclist(const QString &dirpath);
    void startplaymusic();
    void showsongword();
    void changepositionprocebar(qint64 curpos);

   void highlightCurrentLyric();
    void highlightCurrentLyric(int index);
private slots:
    void changemodel();
    void handlebutton();
    void nextsong();
    void upsong();
    void totaltime(qint64 duration);
    void curtime(qint64 position);

    void updateLyricDisplay(qint64 position);//高亮显示
    void handleMediaStatusChange(QMediaPlayer::MediaStatus status);

    void checkchangesong(QListWidgetItem *item);


private:
    qint64 total;
    musicmodel model;
    Ui::MainWindow *ui;
    QMediaPlayer* m_player;
    QVBoxLayout *winlayout;
    bool star=false;//关闭状态
    QString musicurl;
    QList<double> songtimelist;//歌词时间列表
    QVector<struct LyricLine> v;
    int currentLyricIndex = -1;
    int status=0;//等于0为开始播放否则为继续播放
    qint64 curtimes;//当前时间ms
    qint64 totaltimes;//总时长ms
    bool checkupnext;

};
#endif // MAINWINDOW_H
